package lnu.project.cart.content;

import lnu.project.cart.entity.Product;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;

public class ProductDatabaseHelper extends SQLiteOpenHelper implements
		BaseColumns {
	private static final String DATABASE_NAME = "lnuShoppingDB";
	public static final String DATABASE_TABLE = "products";
	private static final int DATABASE_VERSION = 1;
	private static final String DATABASE_CREATE = "create table "
			+ DATABASE_TABLE + " (" + Product.ID
			+ " integer primary key autoincrement, " + Product.BASKET_ID
			+ " integer not null, " + Product.TYPE_OF_PRODUCT
			+ " integer not null, " + Product.NAME + " string not null, "
			+ Product.BARCODE + " string, " + Product.QUANTITY + " integer, "
			+ Product.WEIGHT + " string, " + Product.PRICE + " string" + ");";

	public ProductDatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
		onCreate(db);
	}
}
